<template>
  <div class="message-container" id="myDiv" ref="myDiv">
    <div class="item" v-for="(item, index) in list" :key="index">
      <div class="title"  @click="getIsRead(item.id)" style="cursor: pointer;">
        <el-badge :is-dot="item.isdot" class="item" style="border:0px;padding-left:0px">{{ item.title }}({{ item.date }})</el-badge>
      </div>
      <div class="content">{{ item.message }}</div>
    </div>
  </div>
</template>

<script>
import { number } from "echarts";
export default {
  props: {
    list: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  mounted() {
    this.list.fill(0);
    if (this.$store.state.total != undefined) {
      for (var m = 0; m < this.list.length; m++) {
        this.list.splice(this.list[m]);
      }
    }
    var param = {};
    this.http.post("/api/zm_message/GetData", param).then((result) => {
      this.$store.state.total = result.rows.length;
      for (var i = 0; i < result.rows.length; i++) {
        var row = result.rows[i];
        if (row != undefined) {
          this.list.push({
            title: row.provmc + "-" + row.citymc + "-" + row.xzqmc,
            message: row.message ,
            date: row.create_time,
            id:row.id,
            isdot:row.isread==0?true:false
          });
        }
      }
    });
  },
  data() {
    return {
      total: 0,
    };
  },
  methods: 
  {
    getIsRead(id)
    {
      console.log(id)
      var param={};
      param["isread"]="1";
      param["id"]=id;
      this.http.post("/api/zm_message/updateIsRead", param).then((result) => {
        console.log(result)
        this.list.fill(0);
        if (this.$store.state.total != undefined) {
          for (var m = 0; m < this.list.length; m++) {
            this.list.splice(this.list[m]);
          }
        }
        var gparam = {};
        this.http.post("/api/zm_message/GetData", gparam).then((result) => {
          this.$store.state.total = result.rows.length;
          for (var i = 0; i < result.rows.length; i++) {
            var row = result.rows[i];
            if (row != undefined) {
              this.list.push({
                title: row.provmc + "-" + row.citymc + "-" + row.xzqmc,
                message: row.message ,
                date: row.create_time,
                id:row.id,
                isdot:row.isread==0?true:false
              });
            }
          }
        });

        if(result.data==127)  //省级质检站
        {
          this.$router.push("/applyautlist" );
        }else{
        this.$router.push("/applylist");
        }
        this.isdot=false;
    });
    }
  }
};
</script>
<style scoped lang="less">
.message-container {
  .title {
    padding-bottom: 10px;
  }
  .item {
    border-bottom: 1px solid #eee;
    padding: 10px 20px;
  }
  .content {
    color: #7e7e7e;
    font-size: 13px;
  }
}
</style>
